package com.yixun.system;

import com.yixun.entity.YxSysUser;
import com.yixun.mapper.UserMapper;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author lbx create by 2021/6/1 9:39
 * @apiNote UserDetailsServiceImpl
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Resource
    private UserMapper userMapper;
    
    @Override
    public UserDetails loadUserByUsername(String username) {
        YxSysUser user = userMapper.getUserByName(username);
        if (user!=null) {
            return user;
        }
        throw new UsernameNotFoundException("用户名不存在");
    }
}
